/*
 * @Author: lineCode 1145938682@qq.com
 * @Date: 2025-08-10 18:52:58
 * @LastEditors: lineCode 1145938682@qq.com
 * @LastEditTime: 2025-08-28 23:36:42
 * @FilePath: /backend/shorthand-modules/shorthand-modules-content/src/main/java/com/angus/modules/content/controller/system/SysFinanceController.java
 */
package com.angus.modules.content.controller.system;

import com.angus.common.core.web.controller.BaseController;
import com.angus.common.core.web.domain.AjaxResult;
import com.angus.modules.content.dto.QueryBaseDto;
import com.angus.modules.content.service.SysFinanceService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 财务
 * @author lineCode
 * @date 2025-08-17
 * @description 财务控制器
 */
@RestController
@RequestMapping("/finance")
public class SysFinanceController extends BaseController {
    @Resource // 订单
    private SysFinanceService sysFinanceService;

    /**
     * 订单列表
     * @param dto 查询参数
     * @param extendParams 扩展查询参数
     * @return 订单列表
     */
    @GetMapping("/getPayFeesList")
    public AjaxResult getPayFeesList(QueryBaseDto dto, @RequestParam Map<String, Object> extendParams) {
        dto.setSearchExtend(new HashMap<>());
        // 遍历所有参数，筛选出以 "searchExtend." 开头的参数
        extendParams.forEach((key, value) -> {
            if (key.startsWith("searchExtend.")) {
                // 截取前缀，如 "searchExtend.payMethod" → "payMethod"
                String mapKey = key.substring("searchExtend.".length());
                dto.getSearchExtend().put(mapKey, value);
            }
        });

        return AjaxResult.success(sysFinanceService.getPayFeesList(dto));
    }

    /**
     * 订单佣金列表
     * @param dto 查询参数
     * @param extendParams 扩展查询参数
     * @return 订单佣金列表
     */
    @GetMapping("/getOrderCommissionList")
    public AjaxResult getOrderCommissionList(QueryBaseDto dto, @RequestParam Map<String, Object> extendParams) {
        dto.setSearchExtend(new HashMap<>());
        // 遍历所有参数，筛选出以 "searchExtend." 开头的参数
        extendParams.forEach((key, value) -> {
            if (key.startsWith("searchExtend.")) {
                // 截取前缀，如 "searchExtend.payMethod" → "payMethod"
                String mapKey = key.substring("searchExtend.".length());
                dto.getSearchExtend().put(mapKey, value);
            }
        });
        return AjaxResult.success(sysFinanceService.getOrderCommissionList(dto));
    }

    /**
     * 订单收益
     * @param dto 查询参数
     * @param extendParams 扩展查询参数
     * @return 订单收益
     */
    @GetMapping("/getPayFeesProfit")
    public AjaxResult getPayFeesProfit(QueryBaseDto dto, @RequestParam Map<String, Object> extendParams) {
        dto.setSearchExtend(new HashMap<>());
        // 遍历所有参数，筛选出以 "searchExtend." 开头的参数
        extendParams.forEach((key, value) -> {
            if (key.startsWith("searchExtend.")) {
                // 截取前缀，如 "searchExtend.payMethod" → "payMethod"
                String mapKey = key.substring("searchExtend.".length());
                dto.getSearchExtend().put(mapKey, value);
            }
        });
        return AjaxResult.success(sysFinanceService.getPayFeesProfit(dto));
    }
}
